<template>
	<view>
		<view class='order-submission'>
			<view class="allAddress" :style="store_self_mention ? '':'padding-top:10rpx'">
				<view class='address acea-row row-between-wrapper' @tap='onAddress'>
					<view class='addressCon' v-if="addressInfo.real_name">
						<view class='name'>{{addressInfo.real_name}}
							<text class='phone'>{{addressInfo.phone}}</text>
						</view>
						<view class="line1">
							<text class='default font-color'
								v-if="addressInfo.is_default">[默认]</text>{{addressInfo.province}}{{addressInfo.city}}{{addressInfo.district}}{{addressInfo.detail}}
						</view>
						<!-- <view class='setaddress'>设置收货地址</view> -->
					</view>
					<view class='addressCon' v-else>
						<view class='setaddress'>设置收货地址</view>
					</view>
					<view class='iconfont icon-jiantou'></view>
				</view>
				<view class='line'>
					<image src='/static/images/line.jpg'></image>
				</view>
			</view>
			<view class='wrapper'>
				<view class='idCardBox' v-if="ishaitaoStatus">
					<view>证件号码:</view>
					<view class="idCardBox_Input">
						<input type="text" v-model="userInfo.idCard" placeholder="请输入证件号码" />
					</view>
				</view>
				<view class='idCardBox' v-if="isMemberCode">
					<view>顾客编号:</view>
					<view class="idCardBox_Input">
						<input type="text" v-model="userInfo.memberCode" placeholder="请输入顾客编号" />
					</view>
				</view>
				<view class='idCardBox' v-if="isMemberCode">
					<view>会员姓名:</view>
					<view class="idCardBox_Input">
						<input type="text" v-model="userInfo.realName" placeholder="请输入会员姓名" />
					</view>
				</view>
			</view>
			<orderGoods :cartInfo="cartInfo" @totalFun="totalFun"></orderGoods>
			<view style='height:120rpx;'></view>
			<view class='footer acea-row row-between-wrapper'>
				<view>合计:
					<text class='font-color'>￥{{totalPrice || 0}}</text>
					<text class='font-color' style="margin-left:20rpx;">PV{{totalPV || 0}}</text>
				</view>
				<view class='settlement' style='z-index:100' @tap="goPay">立即结算</view>
			</view>
		</view>
	</view>
</template>
<script>
	import orderGoods from '@/components/orderGoods/index_zx';
	import home from '@/components/home';
	import {
		getUpSubmit,
		setRetailSubmit,
		setRepeatFormSubmit
	} from '@/api/directSelling.js';
	import {
		mapGetters
	} from "vuex";
	// #ifdef MP
	// #endif
	export default {
		components: {
			orderGoods,
			home,
		},
		data() {
			return {
				address: {
					address: false
				}, //地址组件
				addressInfo: {}, //地址信息
				userInfo: {}, //用户信息
				cartInfo: [], //购物车添加的下单数据
				totalPrice: 0, //下单总计数据
				totalPV: 0, //下单总计PV
				pinkId: 0, //拼团id
				couponId: 0, //优惠券id
				BargainId: 0,
				combinationId: 0,
				seckillId: 0,
				discountId: 0,
				mark: '', //备注信息
				couponTitle: '请选择', //优惠券
				coupon_price: 0, //优惠券抵扣金额
				useIntegral: false, //是否使用积分
				integral_price: 0, //积分抵扣金额
				integral: 0,
				ChangePrice: 0, //使用积分抵扣变动后的金额
				formIds: [], //收集formid
				status: 0,
				toPay: false, //修复进入支付时页面隐藏从新刷新页面
				system_store: {},
				storePostage: 0,
				storeList: [],
				store_self_mention: 0,
				priceGroup: {},
				RegestNewMember: {
					idCard: ""
				},
				saleType: null,
				ishaitaoStatus: false, //判断是否展示证件号码字段
				isMemberCode: false //判断是否展示顾客编号或会员姓名字段
			};
		},
		computed: mapGetters(['isLogin']),
		onLoad: function(options) {
			this.saleType = options.saleType;
			this.userInfo = uni.getStorageSync('userInfo');
			if (options.isAddress) {
				this.getNewAddress();
			} else {
				this.loadAddressInfo(); //加载用户信息
			}
			this.loadCartInfo();
			this.isShowMemberCode();
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {},
		methods: {
			//判断是否显示会员编号以及会员姓名
			isShowMemberCode() {
				if (this.saleType == 1 || this.saleType == 2 || this.saleType == 3 || this.saleType == 30 || this
					.saleType == 14) {
					this.isMemberCode = true
				}
			},
			//加载用户地址信息及用户信息
			loadAddressInfo() {
				this.userInfo = uni.getStorageSync('userInfo');
				this.addressInfo = {
					real_name: this.userInfo.realName, //姓名
					phone: this.userInfo.mobile, //手机号
					province: this.userInfo.provinceDesc=='没有找到地区'?"":this.userInfo.provinceDesc, //省
					city: this.userInfo.cityDesc=='没有找到地区'?"":this.userInfo.cityDesc, //市
					district: this.userInfo.districtDesc=='没有找到地区'?"":this.userInfo.districtDesc, //区县
					detail: this.userInfo.address, //详细地址
					consigneeCountryId: 1,
					consigneeProvinceId: this.userInfo.provinceId,
					consigneeCityId: this.userInfo.cityId,
					consigneeDistrictId: this.userInfo.districtId,
				};
				uni.setStorageSync('addressInfo', this.addressInfo);
			},
			getNewAddress() {
				this.addressInfo = uni.getStorageSync('addressInfo');
				console.log(this.addressInfo);
				console.log("判断");
				console.log(this.userInfo);
			},
			//加载商品信息
			loadCartInfo() {
				let selectValue = uni.getStorageSync('selectValue');
				this.$set(this, 'cartInfo', selectValue);
				this.cartInfo.forEach((ele, ind) => {
					if (ele.isOverseas === 1) {
						this.ishaitaoStatus = true;
					}
				})
			},
			totalFun(data) {
				this.totalPrice = data.totalPrice;
				this.totalPV = data.totalPV;
			},
			//结算数据
			goPay() {
				let that = this;
				let packageInfo = [];
				if (this.totalPV > 0) {
					this.cartInfo.forEach((ele, ind) => {
						packageInfo.push({
							packageId: ele.packageId,
							purchaseQty: ele.prodNum
						})
					})
					let sendData = {
						orderTotalAmounts: this.totalPrice,
						orderTotalPv: this.totalPV,
						orders: {
							consigneeName: this.addressInfo.real_name,
							consigneeMobile: this.addressInfo.phone,
							consigneeAddress: this.addressInfo.detail,
							consigneeCountryId: 1,
							consigneeProvinceId: parseInt(this.addressInfo.consigneeProvinceId),
							consigneeCityId: parseInt(this.addressInfo.consigneeCityId),
							consigneeDistrictId: parseInt(this.addressInfo.consigneeDistrictId),
						},
						packageInfo: packageInfo
					}
					if (this.saleType==5) {//升级订单
						getUpSubmit(sendData).then((res) => {
							let data = res.data;
							if (res.meta.success == true) {
								uni.navigateTo({
									url: '/pages/users/order_confirm/orderDetails?orderId=' + data +
										"&saleType=" + this.saleType
								})
							}

						}).catch((err) => {

						})
					} else if (this.saleType==3) {//零售
						setRetailSubmit(sendData).then((res) => {
							let data = res.data;
							if (res.meta.success == true) {
								uni.navigateTo({
									url: '/pages/users/order_confirm/orderDetails?orderId=' + data +
										"&saleType=" + this.saleType
								})
							}

						}).catch((err) => {

						})
					}else if(this.saleType==2){//冲销
						setRepeatFormSubmit(sendData).then((res) => {
							let data = res.data;
							if (res.meta.success == true) {
								uni.navigateTo({
									url: '/pages/users/order_confirm/orderDetails?orderId=' + data +
										"&saleType=" + this.saleType
								})
							}

						}).catch((err) => {

						})
					}

				} else {
					that.$util.Tips({
						title: 'PV不能为0',
					});
				}
			},
			//编辑收货地址
			onAddress() {
				console.log("点击编辑地址数据");
				uni.navigateTo({
					url: '/pages/users/user_address_list/index_zx?saleType='+this.saleType
				})
			},
			bindHideKeyboard(e) {

			}
		}
	}
</script>

<style lang="scss" scoped>
	/deep/uni-checkbox[disabled] .uni-checkbox-input {
		background-color: #eee;
	}

	.alipaysubmit {
		display: none;
	}

	.order-submission .line {
		width: 100%;
		height: 3rpx;
	}

	.order-submission .line image {
		width: 100%;
		height: 100%;
		display: block;
	}

	.order-submission .address {
		padding: 28rpx 30rpx;
		background-color: #fff;
		box-sizing: border-box;
	}

	.order-submission .address .addressCon {
		width: 610rpx;
		font-size: 26rpx;
		color: #666;
	}

	.order-submission .address .addressCon .name {
		font-size: 30rpx;
		color: #282828;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.order-submission .address .addressCon .name .phone {
		margin-left: 50rpx;
	}

	.order-submission .address .addressCon .default {
		margin-right: 12rpx;
	}

	.order-submission .address .addressCon .setaddress {
		color: #333;
		font-size: 28rpx;
	}

	.order-submission .address .iconfont {
		font-size: 35rpx;
		color: #707070;
	}

	.order-submission .allAddress {
		width: 100%;
		background: linear-gradient(to bottom, #e93323 0%, #f5f5f5 100%);
		// background-image: linear-gradient(to bottom, #e93323 0%, #f5f5f5 100%);
		// background-image: -webkit-linear-gradient(to bottom, #e93323 0%, #f5f5f5 100%);
		// background-image: -moz-linear-gradient(to bottom, #e93323 0%, #f5f5f5 100%);
		padding-top: 100rpx;
	}

	.order-submission .allAddress .nav {
		width: 710rpx;
		margin: 0 auto;
	}

	.order-submission .allAddress .nav .item {
		width: 355rpx;
	}

	.order-submission .allAddress .nav .item.on {
		position: relative;
		width: 250rpx;
	}

	.order-submission .allAddress .nav .item.on::before {
		position: absolute;
		bottom: 0;
		content: "快递配送";
		font-size: 28rpx;
		display: block;
		height: 0;
		width: 336rpx;
		border-width: 0 20rpx 80rpx 0;
		border-style: none solid solid;
		border-color: transparent transparent #fff;
		z-index: 2;
		border-radius: 7rpx 30rpx 0 0;
		text-align: center;
		line-height: 80rpx;
	}

	.order-submission .allAddress .nav .item:nth-of-type(2).on::before {
		content: "到店自提";
		border-width: 0 0 80rpx 20rpx;
		border-radius: 30rpx 7rpx 0 0;
	}

	.order-submission .allAddress .nav .item.on2 {
		position: relative;
	}

	.order-submission .allAddress .nav .item.on2::before {
		position: absolute;
		bottom: 0;
		content: "到店自提";
		font-size: 28rpx;
		display: block;
		height: 0;
		width: 400rpx;
		border-width: 0 0 60rpx 60rpx;
		border-style: none solid solid;
		border-color: transparent transparent #f7c1bd;
		border-radius: 40rpx 6rpx 0 0;
		text-align: center;
		line-height: 60rpx;
	}

	.order-submission .allAddress .nav .item:nth-of-type(1).on2::before {
		content: "快递配送";
		border-width: 0 60rpx 60rpx 0;
		border-radius: 6rpx 40rpx 0 0;
	}

	.order-submission .allAddress .address {
		width: 710rpx;
		height: 150rpx;
		margin: 0 auto;
	}

	.order-submission .allAddress .line {
		width: 710rpx;
		margin: 0 auto;
	}

	.order-submission .wrapper .item .discount .placeholder {
		color: #ccc;
	}

	.placeholder-textarea {
		position: relative;

		.placeholder {
			position: absolute;
			color: #ccc;
			top: 26rpx;
			left: 30rpx;
		}
	}

	.order-submission .wrapper {
		background-color: #fff;
		margin-top: 13rpx;
	}

	.order-submission .wrapper .item {
		padding: 27rpx 30rpx;
		font-size: 30rpx;
		color: #282828;
		border-bottom: 1px solid #f0f0f0;
	}

	.order-submission .wrapper .item .discount {
		font-size: 30rpx;
		color: #999;
	}

	.order-submission .wrapper .item .discount input {
		text-align: end;
	}

	.order-submission .wrapper .item .discount .iconfont {
		color: #515151;
		font-size: 30rpx;
		margin-left: 15rpx;
	}

	.order-submission .wrapper .item .discount .num {
		font-size: 32rpx;
		margin-right: 20rpx;
	}

	.order-submission .wrapper .item .shipping {
		font-size: 30rpx;
		color: #999;
		position: relative;
		padding-right: 58rpx;
	}

	.order-submission .wrapper .item .shipping .iconfont {
		font-size: 35rpx;
		color: #707070;
		position: absolute;
		right: 0;
		top: 50%;
		transform: translateY(-50%);
		margin-left: 30rpx;
	}

	.order-submission .wrapper .item textarea {
		background-color: #f9f9f9;
		width: 690rpx;
		height: 140rpx;
		border-radius: 3rpx;
		margin-top: 30rpx;
		padding: 25rpx 28rpx;
		box-sizing: border-box;
	}

	.order-submission .wrapper .item .placeholder {
		color: #ccc;
	}

	.order-submission .wrapper .item .list {
		margin-top: 35rpx;
	}

	.order-submission .wrapper .item .list .payItem {
		border: 1px solid #eee;
		border-radius: 6rpx;
		height: 86rpx;
		width: 100%;
		box-sizing: border-box;
		margin-top: 20rpx;
		font-size: 28rpx;
		color: #282828;
	}

	.order-submission .wrapper .item .list .payItem.on {
		border-color: #fc5445;
		color: #e93323;
	}

	.order-submission .wrapper .item .list .payItem .name {
		width: 50%;
		text-align: center;
		border-right: 1px solid #eee;
		padding-left: 80rpx;
	}

	.order-submission .wrapper .item .list .payItem .name .iconfont {
		width: 44rpx;
		height: 44rpx;
		border-radius: 50%;
		text-align: center;
		line-height: 44rpx;
		background-color: #fe960f;
		color: #fff;
		font-size: 30rpx;
		margin-right: 15rpx;
	}

	.order-submission .wrapper .item .list .payItem .name .iconfont.icon-weixin2 {
		background-color: #41b035;
	}

	.order-submission .wrapper .item .list .payItem .name .iconfont.icon-zhifubao {
		background-color: #1677FF;
	}

	.order-submission .wrapper .item .list .payItem .tip {
		width: 49%;
		text-align: center;
		font-size: 26rpx;
		color: #aaa;
	}

	.order-submission .moneyList {
		margin-top: 12rpx;
		background-color: #fff;
		padding: 30rpx;
	}

	.order-submission .moneyList .item {
		font-size: 28rpx;
		color: #282828;
	}

	.order-submission .moneyList .item~.item {
		margin-top: 20rpx;
	}

	.order-submission .moneyList .item .money {
		color: #868686;
	}

	.order-submission .footer {
		width: 100%;
		height: 100rpx;
		background-color: #fff;
		padding: 0 30rpx;
		font-size: 28rpx;
		color: #333;
		box-sizing: border-box;
		position: fixed;
		bottom: 0;
		left: 0;
	}

	.order-submission .footer .settlement {
		font-size: 30rpx;
		color: #fff;
		width: 240rpx;
		height: 70rpx;
		background-color: $theme-color;
		border-radius: 50rpx;
		text-align: center;
		line-height: 70rpx;
	}

	.footer .transparent {
		opacity: 0
	}

	.idCardBox {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx;

		.idCardBox_Input {
			text-align: right;

			.uni-input-placeholder {
				font-size: 24rpx;
			}
		}
	}
</style>
